<?php
require('db.php');

$vak = $_GET['vak'];

$result = mysql_query("select c.id, c.omschrijving, c.niveau, c.parentID from competenties c join(select competentieID from competentiespervak where vakID=(select id from vak where naam='$vak')) z on (c.id=z.competentieID)") or die (mysql_error());

$data = array();

while ($row = mysql_fetch_object($result)) {
    $data [] = $row;
}

echo json_encode($data);
?>